import lioncen.cti.jmsi.*;
import lioncen.cti.jmsi.object.*;
import lioncen.cti.jmsi.engine.*;
import javax.servlet.http.Cookie
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import cn.umum.msi.listener.MSIAdapter;
import cn.umum.common.Thief;
import cn.umum.msi.Msiuser;
import grails.converters.JSON
import cn.umum.common.BaseFunction as BF;
class LoginController {
    static def allowedMethods = [setDN:'POST', dialOut:'POST']
    def jsonObj = [];
    def Success=false;
    //render jsonObj as JSON
    def index = {
        flash.message = flash.message;
        redirect(action: 'form')
    }
    def logout={
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            Success=false;
            //redirect(uri: "/login");
        }
        private int agentID,ret;
        private String agentid,logoutmsg;
        agentID=0;
        agentid=cookie(name:"agentID")
        if(agentid!=null){
            agentID=Integer.valueOf(agentid);
        }
        ret=-1;
        logoutmsg="暂未退出";
        ret = msi.logout(agentID);
        if (ret==0){
            logoutmsg="登出成功";
            user=users.remove("A"+agentID);
            MsiInfo msiinfo = MsiInfo.findByAgentIDAndCompanySN(agentid.substring(6,9),agentid.substring(0,6))
            if(msiinfo){
                msiinfo.agtAction="LOGOUT";
                msiinfo.status="AS_OK";
                msiinfo.save();
            }
            if(user==null){
                println("-------user A"+agentID+" not exit--------");
            }
            else{
                println("-------delete A"+agentID+" successed--------");
            }
            flash.message = "退出成功，如需重新登录，请重新输入座席信息"
            Success=true;
        }
        else{
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            Success=false;
        }
        jsonObj =[result:[success:Success,message:flash.message]]
        render jsonObj as JSON;
    }
    def setStats={setStatsCommand cmd ->
        def childuser,parentuser,companysn,msiinfo,domain;
        //render(cmd.agentid.toString().substring(6,9));
        //return;
        if (cmd.hasErrors()) {
            flash.message = "输入错误，请重新输入"
            Success=false;
        }else{
            public static MSI msi = null;
            msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
            if(msi==null){
                flash.message = "操作失败，登录已过期或还未登录，请重新登录"
                Success=false;
            }
            private int agentID;
            private String agentid,agtAction,status;
            agtAction="WORK";
            status="AS_OK";
            flash.message = "闲置成功"
            if(cmd.stat==3){
                agtAction="BUSY";
                flash.message = "忙置成功"
            }
            agentID=0;
            agentid=cookie(name:"agentID");
            if(agentid!=null){
                agentID=Integer.valueOf(agentid);
            }
            int ret=-1;
            //todo下面改用hashmap查找，其他的操作亦然
            //println(agentid.substring(0,6));
            //MsiInfo msiinfo = MsiInfo.findByAgentIDAndCompanySN(agentid.substring(6,9),agentid.substring(0,6))
                childuser=User.findByIdAndTruepassword(cookie(name:"userid"),BF.AESDecryptCtr(URLDecoder.decode(cookie(name:"userpassword")),"ymcookies",256))
                if(childuser==null){render "error";return}
                parentuser=User.findById(childuser.userParentid)
                if(parentuser==null){render "error";return}
                domain=UserDomain.findByDomain(cmd.domain)
                if(domain==null){render "error";return}
                companysn = Companysn.findByUserAndDomain(parentuser,domain);
                if(companysn==null){render "error";return}
                if(cmd.agentid!=null){
                    def msithiinfo = companysn ? MsiInfo.findByCompanySNAndUser(companysn,childuser) : null;
                    if(msithiinfo==null){render "error";return}
                    if(msithisinfo.isMonitor==false){render "error";return}
                    msiinfo= MsiInfo.findByCompanySNAndAgentID(companysn,cmd.agentid.toString().substring(6,9));
                    if(msiinfo==null){render "error";return}
                    agentID=cmd.agentid;
                    ret = msi.setAgentStatusByAgentID(cmd.agentid, cmd.stat);
                }else{
                msiinfo= companysn ? MsiInfo.findByCompanySNAndUser(companysn,childuser) : null;
                if(msiinfo==null){render "error";return}
                ret = msi.setAgentStatus(cmd.stat);
                }
                
            if(msiinfo){
                msiinfo.agtAction=agtAction;
                msiinfo.status=status;
                msiinfo.save();
            }
            
            if (ret==0){
                Msiuser u = MSIAdapter.findUser(MSIAdapter.agentStats, "A"+agentID);
                if(u!=null){
                    user = new Msiuser();
                    user.setUserid("A"+agentID);
                    user.setUsername("username"+agentID);
                    user.setagentDN(u.getagentDN());
                    user.setUserStat(cmd.stat);
                    users.put("A"+agentID,user);
                    MSIAdapter.agentStatsChange.put("A"+agentID,user);
                }
                Success=true;
            }else{
                flash.message = "操作失败，登录已过期或还未登录，请重新登录"
                Success=false;
            }
        }
        //jsonObj =[result:[success:Success,message:flash.message]]
        //render jsonObj as JSON;
        render flash.message;
    }
    def setDND={
        if(params.id==null){
            render "error";
        }
        int mode = Integer.valueOf(params.id)
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            //redirect(uri: "/login");
            render(flash.message);
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret=-1;
        MsiInfo msiinfo = MsiInfo.findByAgentID(agentID)
        if(msiinfo){
            msiinfo.agtAction="WORK";
            msiinfo.status="AS_OK";
            msiinfo.save();
        }
        ret=msi.setDND(mode);
        if(ret==0){
            flash.message = "setDND"+mode+"成功"
            //redirect(uri: "/msi/userinfo");
            render(flash.message);
        }else{
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            //redirect(uri: "/login");
            render(flash.message);
        }
        
    }   
    def setCallProtect={
        if(params.id==null){
            render "error";
        }
        int mode = Integer.valueOf(params.id)
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            redirect(uri: "/login");
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret=-1;
        MsiInfo msiinfo = MsiInfo.findByAgentID(agentID)
        if(msiinfo){
            msiinfo.agtAction="WORK";
            msiinfo.status="AS_OK";
            msiinfo.save();
        }
        ret=msi.setCallProtect(mode);
        if(ret==0){
            flash.message = "setCallProtect"+mode+"成功"
            redirect(uri: "/msi/userinfo");
        }else{
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            redirect(uri: "/login");
        }

    }
    def setBusyCallBack={
        if(params.id==null){
            render "error";
        }
        int mode = Integer.valueOf(params.id)
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            redirect(uri: "/login");
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret=-1;
        MsiInfo msiinfo = MsiInfo.findByAgentID(agentID)
        if(msiinfo){
            msiinfo.agtAction="WORK";
            msiinfo.status="AS_OK";
            msiinfo.save();
        }
        ret=msi.setBusyCallBack(mode);
        if(ret==0){
            flash.message = "setCallProtect"+mode+"成功"
            redirect(uri: "/msi/userinfo");
        }else{
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            redirect(uri: "/login");
        }

    }
    //摘机后让主叫保持等待状态
    def hold={
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            Success=false;
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret = msi.hold();
        if (ret == CTIConst.RET_FAIL)
        {
            flash.message ="挂起操作失败:" + msi.getLastErrorString();
            Success=false;
        } else
        {
            flash.message ="保持操作成功";
            Success=true;
        }
        //flash.message = "保持成功"
        //redirect(uri: "/msi/userinfo");
        jsonObj =[result:[success:Success,message:flash.message]]
        render jsonObj as JSON;
    }
    //执行hold后接回操作
    def retrieve={
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            Success=false;
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret = msi.retrieve();
        if (ret == CTIConst.RET_FAIL)
        {
            flash.message ="挂起操作失败:" + msi.getLastErrorString();
            Success=false;
        } else
        {
            flash.message ="接回操作成功";
            Success=true;
        }
        jsonObj =[result:[success:Success,message:flash.message]]
        render jsonObj as JSON;
    }
    def completeTrans={
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            redirect(uri: "/login");
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret = msi.transferEx("1003", "", 1, cookie(name:"accdns"));
        if (ret == CTIConst.RET_FAIL)
        {
            println("转移操作失败:" + msi.getLastErrorString());
        } else
        {
            println("转移操作成功");
        }
        flash.message = "转移成功"
        redirect(uri: "/msi/userinfo");
    }
    def transferEx={
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        if(msi==null){
            flash.message = "操作失败，登录已过期或还未登录，请重新登录"
            redirect(uri: "/login");
        }
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret = msi.completeTrans();
        if (ret == CTIConst.RET_FAIL)
        {
            println("转移操作失败:" + msi.getLastErrorString());
        } else
        {
            println("转移操作成功");
        }
        flash.message = "转移成功"
        redirect(uri: "/msi/userinfo");
    }

    def initTrans={
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        private int agentID;
        agentID=0;
        if(cookie(name:"agentID")!=null){
            agentID=Integer.valueOf(cookie(name:"agentID"));
        }
        int ret = msi.initTrans("1003", "", false);
        if (ret == CTIConst.RET_FAIL)
        {
            println("转移操作失败:" + msi.getLastErrorString());
        } else
        {
            println("转移操作成功");
        }
        flash.message = "转移成功"
        redirect(uri: "/msi/userinfo");
    }
    
    def dialOut = {DialOutCommand cmd ->
        if (cmd.hasErrors()) {
            flash.message = "电话号码输入错误，请重新输入"
            redirect(action: 'dialoutform')
        } else {
            public static MSI msi = null;
            msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
            if(msi==null){
                flash.message = "操作失败，登录已过期或还未登录，请重新登录"
                redirect(uri: "/login");
            }
            private int agentID;
            agentID=0;
            if(cookie(name:"agentID")!=null){
                agentID=Integer.valueOf(cookie(name:"agentID"));
            }
            println agentID;
            int ret=-1;
            MsiInfo msiinfo = MsiInfo.findByAgentID(agentID)
            String loginmsg;
            boolean islogin=0;
            int i=0;
            ret=msi.dialout(msiinfo.agentDN, -1, "", false);
            if (ret==0){
                islogin=1;
                loginmsg="successed";
                int iRet=-1;
                iRet=msi.dialout(cmd.agentDN, -1, "", false);
                if (iRet==0){
                    render "dailout successed";
                }
                else{
                    render "dialout failed";
                }

            }
            else{
                loginmsg="dialout failed";
            }
            render loginmsg;
        }
    }

    def joinAcd={JoinAcdCommand cmd ->
        if (cmd.hasErrors()) {
            flash.message = "登录错误，请重新输入"
            Success=false;
        }
        else {
            public static MSI msi = null;
            msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
            if(msi==null){
                flash.message ="暂未连接cti或cti服务器已关闭";
                Success=false;
            }
            else{
                private String agentDN,accdns;
                private int agentID;
                agentID=Integer.valueOf(cookie(name:"agentID"));
                int ret=msi.joinAcd(agentID, cmd.accdns, 5)
                if (ret == CTIConst.RET_FAIL)
                {
                    flash.message ="加入ACD失败:" + msi.getLastErrorString();
                    Success=false;
                } else
                {
                    flash.message ="加入ACD成功,agentID=" + agentID;
                    Success=true;
                }
            }
        }
        jsonObj =[result:[success:Success,message:flash.message]]
        render jsonObj as JSON;
    }
    def leaveAcd={JoinAcdCommand cmd ->
        if (cmd.hasErrors()) {
            flash.message = "操作错误，请重新输入"
            Success=false;
        }
        else {
            public static MSI msi = null;
            msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
            if(msi==null){
                flash.message ="暂未连接cti或cti服务器已关闭";
                Success=false;
            }
            else{
                private String agentDN,accdns;
                private int agentID;
                agentID=Integer.valueOf(cookie(name:"agentID"));
                int ret=msi.leaveAcd(agentID, cmd.accdns)
                if (ret == CTIConst.RET_FAIL)
                {
                    flash.message="离开ACD失败:" + msi.getLastErrorString();
                    Success=false;
                } else
                {
                    flash.message="离开ACD成功,agentID=" + agentID ;
                    Success=true;
                }
            }
        }
        jsonObj =[result:[success:Success,message:flash.message]]
        render jsonObj as JSON;
    }

    def login = {  MsiLoginCommand cmd ->
        if (cmd.hasErrors()) {
            flash.message = "登录错误，请重新输入"
            Success=false;
        } else {
            public static MSI msi = null;
            msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
            if(msi==null){
                //println("saa");
                flash.message="暂未连接cti或cti服务器已关闭";
                Success=false;
            }
            else{
                private String agentDN,accdns,loginmsg;
                private int agentID,ret;
                private boolean	isMonitor,isSilentMode
                def arr=[]
                loginmsg="登录失败，可能该座席已经登录或者呼叫中心暂时无法连接";
                ret = CTIConst.RET_FAIL;
                println("Attempting login")
            
                /*Thief ct = new Thief("http://www.umum.cn/users/logininfo.asp?password="+cmd.password+"&userid="+cmd.userid,"utf-8");
                //ct.setProxy("127.0.0.1","9666");
                //render("http://www.umum.cn/users/logininfo.asp?password="+cmd.password+"&userid="+cmd.userid+"<br />")
                boolean rt = ct.thief();
                if(ct.getValue()!=null){
                ct.clearReturn();
                ct.clearSpace();
                arr=ct.getValue().split("\\|");
                agentID=Integer.valueOf(arr[1]+arr[0]);
                agentDN=arr[3].replace("027-","");
                agentDN=agentDN.replace("-","");
                agentDN="9"+agentDN;
                //render("accdnses=");
                }
                else
                {
                //render("accdnses=");
                flash.message =ct.getErrText();
                Success=false;
                }
                println(arr[1]);*/
                //6oWfSc%2FPz894ut5G2YOBR63F2IkxfanW
                def childuser=User.findByIdAndTruepassword(cookie(name:"userid"),BF.AESDecryptCtr(URLDecoder.decode(cookie(name:"userpassword")),"ymcookies",256))
                if(childuser==null){render "error";return}
                def parentuser=User.findById(childuser.userParentid)
                if(parentuser==null){render "error";return}
                def domain=UserDomain.findByDomain(cmd.domain)
                if(domain==null){render "error";return}
                def companysn = Companysn.findByUserAndDomain(parentuser,domain);
                if(companysn==null){render "error";return}
                def msiinfo = companysn ? MsiInfo.findByCompanySNAndUser(companysn,childuser) : null;
                if(msiinfo==null){render "error";return}
                //render msiinfo;
                /*
                //MsiInfo msiinfo = MsiInfo.findByAgentIDAndUserIDAndCompanySN(arr[1],params.userid,companysn)
                MsiInfo msiinfo = MsiInfo.findWhere(agentID:arr[1],userID:Integer.valueOf(params.userid),companySN:companysn)
                //render("accdnses="+msiinfo.accdnses);
                 */
                if (msiinfo) {
                    //agentDN=msiinfo.agentDN;
                    def accdnses="";
                    for(a in msiinfo.accdnses.dns){
                        if(accdnses==""){
                            accdnses=a.value.toString()+msiinfo.companySN.companySN
                        }
                        else{
                            accdnses=accdnses.toString()+";"+a.value+msiinfo.companySN.companySN
                        }
                    }
                    agentDN=msiinfo.agentDN.replace("027-","");
                    agentDN=agentDN.replace("-","");
                    agentDN="9"+agentDN;
                    msi.setDN(agentDN);
                    println(agentDN)
                    accdns=accdnses;
                    //render("accdnses="+accdns);
                    isMonitor=0;
                    isSilentMode=0;
                    if(msiinfo.isMonitor=="true"){
                        isMonitor=1;
                    }
                    if(msiinfo.isSilent=="true"){
                        isSilentMode=1;
                    }
                    boolean islogin=0;
                    int i=0;
                    agentID=Integer.valueOf(msiinfo.companySN.companySN+msiinfo.agentID)
                    msi.logout(agentID);
                    ret=msi.login(agentID, isMonitor, isSilentMode,accdns, "-1", "xms", "");
                    if (ret==0){
                        islogin=1;
                        loginmsg="successed";
                        
                    }
                    else{
                        loginmsg="failed";
                    }
            
                    println(loginmsg+msi.getLastErrorString())
                    switch (loginmsg){
                        case "successed":
                        msiinfo.agtAction="WORK";
                        msiinfo.status="AS_OK";
                        msiinfo.save();
                        user = new Msiuser();
                        user.setUserid("A"+agentID);
                        user.setUsername("username"+agentID);
                        user.setagentDN(agentDN);
                        user.setUserStat(2);
                        users.put("A"+agentID,user);
                        MSIAdapter.agentStatsChange.put("A"+agentID,user);
                        
                        Cookie msicookie = new Cookie("agentID",String.valueOf(agentID))
                        msicookie.setMaxAge(60*60*24*30);
                        msicookie.setPath("/msi/");
                        response.addCookie(msicookie)
                        Cookie msicookie1 = new Cookie("accdns",accdns)
                        msicookie1.setMaxAge(60*60*24*30);
                        msicookie1.setPath("/msi/");
                        response.addCookie(msicookie1)
                        Cookie msicookie2 = new Cookie("isSilent",Boolean.toString(msiinfo.isSilent))
                        msicookie2.setMaxAge(60*60*24*30);
                        msicookie2.setPath("/msi/");
                        response.addCookie(msicookie2)
                        Cookie msicookie3 = new Cookie("agentDN",msiinfo.agentDN)
                        msicookie3.setMaxAge(60*60*24*30);
                        msicookie3.setPath("/msi/");
                        response.addCookie(msicookie3)
                        flash.message="login ok";
                        Success=true;
                        break;
                        default:
                        flash.message = "登录失败，可能cti服务器已经关闭"+msi.getLastErrorString();
                        Success=false;
                    }
                } else {
                    println("login failed")
                    flash.message = "错误的座席编号或登录密码，请重新输入"
                    Success=false;
                }
            }
        }
        jsonObj =[result:[success:Success,message:flash.message]]
        render jsonObj as JSON;
        
        // render jsonObj.result;
    }

    def setDN = {DialOutCommand cmd ->
        //render request.form["relogin"]
        //render request.getParameter("relogin")
        public static MSI msi = null;
        msi = servletContext.getAttribute("msi"+cookie(name:"MSI-JSESSIONID"));
        //msi.ctiEventListener = new MyMSIEventHandler();
        private int agentID;
        if (cmd.hasErrors()) {
            flash.message = "电话号码输入错误，请重新输入"+request.getParameter("relogin")
            redirect(action: 'setdnform')
        } else {
            agentID=0;
            if(cookie(name:"agentID")!=null){
                agentID=Integer.valueOf(cookie(name:"agentID"));
            }
            println agentID;
            int ret=-1;
            MsiInfo msiinfo = MsiInfo.findByAgentID(agentID)
            private String agentDN,ctiIP,accdns;
            private boolean isMonitor,isSilentMode
            String loginmsg;
            boolean islogin=0;
            int i=0;
            if (msiinfo) {
                msi.setDN(cmd.agentDN);
                accdns=msiinfo.accdns;
                isMonitor=0;
                isSilentMode=0;
                if(msiinfo.isMonitor=="true"){
                    isMonitor=1;
                }
                if(msiinfo.isSilent=="true"){
                    isSilentMode=1;
                }
                while(!islogin){
                    msi.logout(agentID);
                    ret=msi.login(agentID, isMonitor, isSilentMode,accdns, "-1", "xms", "");
                    if (ret==0){
                        islogin=1;
                        loginmsg="successed";
                        //MSIAdapter.users;

                    }
                    else{
                        if(i==19)
                        {
                            islogin=1;
                            loginmsg="failed";
                        }
                        i=i+1;
                        println i;
                    }
                }
                switch (loginmsg){
                    case "successed":
                    msiinfo.agentDN=cmd.agentDN;
                    msiinfo.save();
                    Cookie msicookie = new Cookie("agentID",msiinfo.agentID)
                    msicookie.setMaxAge(60*60*24*30);
                    msicookie.setPath("/msi/");
                    response.addCookie(msicookie)
                    Cookie msicookie1 = new Cookie("accdns",msiinfo.accdns)
                    msicookie1.setMaxAge(60*60*24*30);
                    msicookie1.setPath("/msi/");
                    response.addCookie(msicookie1)
                    Cookie msicookie2 = new Cookie("isSilent",Boolean.toString(msiinfo.isSilent))
                    msicookie2.setMaxAge(60*60*24*30);
                    msicookie2.setPath("/msi/");
                    response.addCookie(msicookie2)
                    Cookie msicookie3 = new Cookie("agentDN",msiinfo.agentDN)
                    msicookie3.setMaxAge(60*60*24*30);
                    msicookie3.setPath("/msi/");
                    response.addCookie(msicookie3)
                    //isSilent
                    //render msiinfo.agentID;
                    redirect(uri: "/msi/userinfo/");
                    break;
                    default:
                    render "failed"
                }
                //render loginmsg;
            }
        }
    }
    def dialoutform = {

    }
    def setdnform={
        
    }
    def joinacdform={

    }
    def leaveacdform={

    }
    def acdform={
        
    }
    
    Msiuser user;
    public static Map<String, Msiuser> users = MSIAdapter.agentStats;

}


class setStatsCommand{
    String domain
    Integer stat
    Integer agentid
    static constraints = {
        domain(blank:false)
        stat(blank:false)
    }
}
class DialOutCommand {
    String agentDN
    static constraints = {
        agentDN(blank:false)
    }

}
class JoinAcdCommand{
    String accdns
    static contraints={
        accdns(blank:false)
    }
}


